<template>
	<view>
		<uni-list>
			<uni-list-item v-for="(item,index) in options" :key="index" :title="item.key" :rightText="item.value">
			</uni-list-item>
		</uni-list>
		<!-- 后送弹窗 -->
		<uni-popup ref="popup" background-color="#fff"  >
			<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
					<view class="example">
						<uni-forms ref="baseForm" :modelValue="baseFormData" label-width="100px">
							<uni-forms-item label="类型" class="wounded">
								<uni-data-checkbox style="margin-top: 10rpx;" v-model="baseFormData.lx" :localdata="lx" />
							</uni-forms-item>
							<uni-forms-item label="批次号" class="wounded">
								<uni-easyinput disabled="" v-model="baseFormData.pch"/>
							</uni-forms-item>
							<uni-forms-item label="方式" class="wounded">
								<uni-data-checkbox style="margin-top: 10rpx;" v-model="baseFormData.fs" :localdata="fs" />
							</uni-forms-item>
							<uni-forms-item label="送往" class="wounded">
								<uni-easyinput v-model="baseFormData.sw"/>
							</uni-forms-item>
							<uni-forms-item label="说明" class="wounded">
								<uni-easyinput type="textarea" v-model="baseFormData.bz"/>
							</uni-forms-item>
						</uni-forms>
					</view>
					<view class="fixedBottom">
						<button class="trueDecide" @click="trueDecide()">确定</button>
						<button class="cancel" @click="cancel()">取消</button>
					</view>
			</view>
		</uni-popup>
		<!-- 驳回弹窗 -->
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose"  mode="input" title="驳回原因"
				placeholder="请输入驳回原因" @confirm="dialogInputConfirm"></uni-popup-dialog>
		</uni-popup>
		<!-- <view class="fixedBottom">
			<button  @click="evacuation()">后送</button>
			<button  @click="overrule()">驳回</button>
		</view> -->
	</view>
</template>

<script>
	import { dictionary,lotNumber, evacuationConfirm, overrule } from '../../api/huanzhe.js'
	import { toast  } from '../../utils/utils.js'
	export default {
		data() {
			return {
				fs:[],
				lx:[],
				bh:[],
				baseFormData:{},
				options: [],
				key: [{
						key: '患者姓名',
						value: 'xm'
					},
					{
						key: '所属组',
						value: 'ssz'
					},
					{
						key: '申请时间',
						value: 'sj'
					},
					{
						key: '体位',
						value: 'tw'
					},
					{
						key: '担架',
						value: 'dj'
					},
					{
						key: '说明',
						value: 'bz'
					},
					{
						key: '状态',
						value: 'zt',
					}
				],
				id:null
			}
		},
		onLoad(option){
			var query=JSON.parse(option.data)
			this.key.forEach((item,index)=>{
				var key={
					value:query[item.value],
					key:item.key
				}
				this.options.push(key)
			})
			this.id=query.id
			this.typeInjure()
			this.manner()
		},
		methods: {
			cancel(){
				this.$refs.popup.close()
			},
			// 驳回确认
			dialogInputConfirm(e){
				var bh={
					id:this.id,
					bhyy:e
				}
				this.bh.push(bh)
				overrule(this.bh).then(res=>{
					toast(res.msg)
					if(res.code===200){
						uni.navigateTo({
							url:'/pages/evacuation/index'
						})
					}
				})
			},
			trueDecide(){
				var query={
					bz:this.baseFormData.bz,
					fs:this.baseFormData.fs,
					lx:this.baseFormData.lx,
					pch:this.baseFormData.pch,
					sw:this.baseFormData.sw,
					cqhsId:[this.id]
				}
				evacuationConfirm(query).then(res=>{
					toast(res.msg)
					if(res.cede===200){
						this.$refs.popup.close()
						this.baseFormData={}
						uni.navigateTo({
							url:'/pages/evacuation/index'
						})
					}else{
						this.$refs.popup.close()
					}
				})
			},
			// 批次号查询
			lotNumbers(){
				lotNumber().then(res=>{
					this.baseFormData.pch=(parseInt(res.data)+1);
				})
			},
			// 方式查询
			manner(){
				dictionary('weiqin_housong_fangshi').then(res=>{
					res.data.forEach((item,index)=>{
						var fs={
							value:item.dictValue,
							text:item.dictLabel
						}
						this.fs.push(fs)
					})
				})
			},
			// 类型查询
			typeInjure(){
				dictionary('weiqin_housong_leixing').then(res=>{
					res.data.forEach((item,index)=>{
						var lx={
							value:item.dictValue,
							text:item.dictLabel
						}
						this.lx.push(lx)
					})
				})
			},
			evacuation(){
				this.$refs.popup.open('bottom')
				this.lotNumbers()
			},
			overrule(){
				this.$refs.inputDialog.open()
				// uni.navigateTo({
				// 	url:'/pages/evacuation/index'
				// })
			}
		}
	}
</script>

<style lang="scss">
::v-deep.uni-section .uni-section-header__decoration{
    margin-right: 6px;
    background-color: #23440d;
}
	.popup-content {
		align-items: center;
		justify-content: center;
		padding: 15px;
		height: 900rpx;
		background-color: #fff;
	}

	.popup-height {
		width: 500px;
	}
.fixedBottom{
		height: 200rpx;
		background-color: #FFF;
		position: fixed;
		bottom: 0rpx;
		left: 0;
		right: 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		z-index: 50;
		button{
			width: 300rpx;
			height: 88rpx;
			color: white;
			background-color: #23440d;
			border-radius: 20px;
			line-height: 88rpx;
			text-align: center;
		}
	}
</style>